package com.lgqz.himalayafm.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lgqz.himalayafm.R;
import com.lgqz.himalayafm.adapter.DiscoverAdapter;

import java.util.LinkedList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class LoadFragment extends Fragment {
    private String[] titles;
    private List<Fragment> fragments;

    public LoadFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titles = new String[]{"专辑", "声音", "下载中"};

        fragments = new LinkedList<>();
        fragments.add(new LoadAlbumFragment());
        fragments.add(new LoadVoiceFragment());
        fragments.add(new LoadIngFragment());
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_load, container, false);
    }
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Toolbar toolbar = (Toolbar) view.findViewById(R.id.load_toolbar);
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.load_title);
        ViewPager viewPager = (ViewPager) view.findViewById(R.id.load_viewpager);
        viewPager.setOffscreenPageLimit(2);

        DiscoverAdapter adapter = new DiscoverAdapter(getFragmentManager(), titles, fragments);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}
